package cn.daomeng.firebird.core.config;

import cn.daomeng.firebird.core.log.LogFactory;
import cn.daomeng.firebird.core.xss.XssFilter;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @author: wangcheng04
 * @create: 2019-03-26 14:39
 **/
@Configuration
@PropertySource(value={"classpath:calorie-core.properties"},ignoreResourceNotFound = true,encoding = "UTF-8")
@ConditionalOnProperty(
        name = {"calorie.xss.filter"},
        havingValue = "true",
        matchIfMissing = true
)
public class XssConfiguration {

    @Value("${calorie.xss.filter}")
    private String appName;

    public XssConfiguration() {
        LogFactory.info("SecurityConfiguration 构造");
    }

    @Bean
    public FilterRegistrationBean xssFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        XssFilter xssFilter = new XssFilter();
        registration.setFilter(xssFilter);
        registration.addUrlPatterns(new String[]{"/*"});
        registration.setOrder(1);
        return registration;
    }
}
